@extends('layout.master')

@section('title','添加活动')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ asset('date/shijian.css') }}"/>

@endsection
@section('main')

    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
            <input type="hidden" id="status" name="status" value="{{ session('status') }}">
        </div>
    @endif

    <div class="row">

        <div class="col-lg-12 col-md-12">
            <div class="white-box">
                <form class="form-horizontal form-material" id="publish" method="post" enctype="multipart/form-data">
                    <div class="row">
                        <div class="col-md-12 col-sm-8">
                            <div class="row">
                                <div class="col-md-3 col-sm-6">
                                    <div class="form-group">
                                        <label class="col-md-12">活动名称</label>
                                        <div class="col-md-12">
                                            <input type="text" name="aname"
                                                   class="form-control form-control-line" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-3 col-sm-6">
                                    <label class="control-label">活动类型</label>
                                    <div class="example">
                                        <select style="height: 38px" name="type">
                                            @foreach (App\Commodity::$CuxiaoTypeDisplay as $key => $value)
                                                @if($key!==0)
                                                    <option value="{{ $key }}">{{ $value }}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-3 col-sm-6">
                                    <div class="form-group">
                                        <label class="col-md-12">开团人数</label>
                                        <div class="col-md-12">
                                            <input type="text" name="sunm"
                                                   class="form-control form-control-line" required>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3 col-sm-6">
                                    <div class="form-group">
                                        <label class="col-md-12">获奖人数</label>
                                        <div class="col-md-12">
                                            <input type="text" name="win_num"
                                                   class="form-control form-control-line" required>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-6 col-sm-12">
                                    <div class="col-md-10 col-sm-10">
                                        <div class="form-group">
                                            <label class="control-label">开始时间</label>
                                            <input type="text"  id="start_time" name="start_time" class="form-control form-control-line" required value=""/>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-6 col-sm-12">
                                    <div class="form-group">
                                        <label class="control-label">结束时间</label>
                                        <input type="text"  id="end_time" name="end_time" class="form-control form-control-line" required value=""/>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12 col-sm-12">
                                    <div id="push-booter">
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <label class="control-label">活动介绍</label>
                                                <textarea style="height: 150px; width: 100%;overflow:auto;"
                                                          name="introduce"
                                                          id="introduce"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">添加活动
                                </button>
                                {!! csrf_field() !!}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script src="{{ asset('date/jquer_shijian.js?ver=1" type="text/javascript') }}" charset="utf-8"></script>
    <script type="text/javascript">

        jQuery(document).ready(function () {

            $('.summernote').summernote({
                height: 350, // set editor height
                minHeight: null, // set minimum height of editor
                maxHeight: null, // set maximum height of editor
                focus: false, // set focus to editable area after initializing summernote$('.summernote').summernote({
                toolbar: [
                    // [groupName, [list of button]]
                    ['style', ['bold', 'italic', 'underline', 'clear']],
                    ['fontsize', ['fontsize']],
                    ['fontname', ['fontname']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['height', ['height']],
                    ['insert', ['link', 'picture', 'video']],
                    ['view', ['fullscreen', 'codeview', 'help']]
                ],
                lang: 'zh-CN',
                // placeholder: '内容',
                dialogsFade: true,
            });

            $('.inline-editor').summernote({
                airMode: true
            });

        });

        $(".bt-switch input[type='checkbox'], .bt-switch input[type='radio']").bootstrapSwitch();
        var radioswitch = function () {
            var bt = function () {
                $(".radio-switch").on("switch-change", function () {
                    $(".radio-switch").bootstrapSwitch("toggleRadioState")
                }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck")
                    }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck", !1)
                    })
            };
            return {
                init: function () {
                    bt()
                }
            }
        }();
        $(document).ready(function () {
            radioswitch.init()
        });


        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                if ($('#status').val() == 1) {
                    toastsuccess($('#message').val());
                } else {
                    toasterror($('#message').val());
                }
            }
        });
        $("#start_time").shijian();
        $("#end_time").shijian();

        $("#publish").submit(function (e) {
            e.preventDefault();
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/activity/activityPublish',
                        data: $('#publish').serialize(),// 你的formid
                        async: false,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        error: function (err) {
                            for (var j in err.responseJSON) {
                                err.responseJSON[j].forEach(function (item, index) {
                                    swal(item);
                                })
                            }
                        },
                        success: function (data) {
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    window.location.href = "/activity/activityList";
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    });
                })
        });


    </script>
@endsection